

/*
* Copyright @ 2017 com.iflysse.trains
* crm 下午7:30:41
* All right reserved.
*
*/
	
package com.qf.service.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import com.qf.dao.CrmClassDao;
import com.qf.dao.CrmStaffDao;
import com.qf.dao.CrmStudentDao;
import com.qf.dto.CrmRunoffDto;
import com.qf.dto.CrmStationDto;
import com.qf.dto.CrmStudentDto;
import com.qf.pojo.CrmRunoff;
import com.qf.pojo.CrmStation;
import com.qf.pojo.CrmStudent;
import com.qf.pojo.PageRunoff;
import com.qf.pojo.PageStation;
import com.qf.pojo.PageStudent;
import com.qf.service.CrmStudentService;
import com.qf.utils.DateUtil;

/**
* @desc: crm
* @descripe:XXXX
* @author: 周锐
* @createTime: 2017年7月27日 下午7:30:41
* @history:
* @version: v1.0

*/

public class CrmStudentServiceImpl implements CrmStudentService {
     private CrmStudentDao studentDao;
     private CrmStaffDao sd;
     private CrmClassDao classdao;
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#addCrmStudent(com.qf.pojo.CrmStudent)
	*/

	
	
	/**
	* @param sd the sd to set
	*/
	
	public void setSd(CrmStaffDao sd) {
	
		this.sd = sd;
	}

	
	/**
	* @param classdao the classdao to set
	*/
	
	public void setClassdao(CrmClassDao classdao) {
	
		this.classdao = classdao;
	}

	/**
	* @param studentDao the studentDao to set
	*/
	
	public void setStudentDao(CrmStudentDao studentDao) {
	
		this.studentDao = studentDao;
	}

	@Override
	public void addCrmStudent(CrmStudent student) {

		studentDao.addCrmStudent(student);

	}

	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#updateCrmStudent(com.qf.pojo.CrmStudent)
	*/

	@Override
	public void updateCrmStudent(CrmStudent student) {

		studentDao.updateCrmStudent(student);

	}

	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#findCrmStudentbyId(java.lang.Long)
	*/

	@Override
	public CrmStudent findCrmStudentbyId(Long studentId) {

		//TODO
		return studentDao.findCrmStudentbyId(studentId);

	}

	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#findStudentByPage(int, int)
	*/

	@Override
	public PageStudent findStudentByPage(int page, int size) {

		//TODO
		List<CrmStudent> crmStudent = studentDao.findStudentByPage(page, size);
		List<CrmStudentDto> studentDtos=new ArrayList<>();
		for(CrmStudent student:crmStudent){
			CrmStudentDto studentDto=new CrmStudentDto();
			studentDto.setStudentId(student.getStudentId());
			studentDto.setClassId(student.getCrmClass().getClassId());
			studentDto.setClassName(student.getCrmClass().getClassName());
			studentDto.setBeginTime(DateUtil.tranfaceString(student.getCrmClass().getBeginTime()));
			studentDto.setStuName(student.getStuName());
			studentDto.setTelephone(student.getTelephone());
			studentDto.setIdentity(student.getIdentity());
			studentDto.setQq(student.getQq());
			studentDto.setGender(student.getGender());
			studentDto.setMustTuition(student.getMustTuition());
			studentDto.setActualTuition(student.getActualTuition());
			studentDto.setEmail(student.getEmail());
			studentDto.setSchool(student.getSchool());
			studentDto.setEducation(student.getEducation());
			studentDto.setProfessional(student.getProfessional());
			studentDto.setIdentityAddress(student.getIdentityAddress());
			studentDto.setAddress(student.getAddress());
			studentDto.setRemark(student.getRemark());
			studentDto.setHomeTelephone(student.getHomeTelephone());
			studentDto.setHomeContact(student.getHomeContact());
			studentDto.setStatus(student.getStatus());
			studentDtos.add(studentDto);
		}
		int count = studentDao.findStudentpage();
		int totalpage=(count-1)/size+1;
		return new PageStudent(page,size,totalpage,studentDtos);

	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#findstudentcount()
	*/
		

	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#findCrmStudentDtobyId(java.lang.Long)
	*/
		
	@Override
	public CrmStudentDto findCrmStudentDtobyId(Long studentId) {
		
		CrmStudent student = studentDao.findCrmStudentbyId(studentId);
		CrmStudentDto studentDto=new CrmStudentDto();
		studentDto.setStudentId(student.getStudentId());
		studentDto.setClassId(student.getCrmClass().getClassId());
		studentDto.setClassName(student.getCrmClass().getClassName());
		studentDto.setCourseTypeId(student.getCrmClass().getCrmCourseType().getCourseTypeId());
		studentDto.setCourseName(student.getCrmClass().getCrmCourseType().getCourseName());
		studentDto.setBeginTime(DateUtil.tranfaceString(student.getCrmClass().getBeginTime()));
		studentDto.setStuName(student.getStuName());
		studentDto.setTelephone(student.getTelephone());
		studentDto.setIdentity(student.getIdentity());
		studentDto.setQq(student.getQq());
		studentDto.setGender(student.getGender());
		studentDto.setMustTuition(student.getMustTuition());
		studentDto.setActualTuition(student.getActualTuition());
		studentDto.setEmail(student.getEmail());
		studentDto.setSchool(student.getSchool());
		studentDto.setEducation(student.getEducation());
		studentDto.setProfessional(student.getProfessional());
		studentDto.setIdentityAddress(student.getIdentityAddress());
		studentDto.setAddress(student.getAddress());
		studentDto.setRemark(student.getRemark());
		studentDto.setHomeTelephone(student.getHomeTelephone());
		studentDto.setHomeContact(student.getHomeContact());
		studentDto.setStatus(student.getStatus());
		return studentDto;
			
	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#addStation(com.qf.pojo.CrmStation)
	*/
		
	@Override
	public void addStation(CrmStation station) {
		
		studentDao.addStation(station);
			
	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#updateStation(com.qf.pojo.CrmStation)
	*/
		
	@Override
	public void updateStation(CrmStation station) {
		
		studentDao.updateStation(station);
			
	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#findStationById(java.lang.Integer)
	*/
		
	@Override
	public CrmStation findStationById(Integer stationId) {
		
	    
		return studentDao.findStationById(stationId);
			
	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#findStationByPage(int, int)
	*/
		
	@Override
	public PageStation findStationByPage(int page, int size) {
		
		List<CrmStation> list = studentDao.findStationByPage(page, size);
		List<CrmStationDto> stationDtos=new ArrayList<>();
		for(CrmStation station:list){
			CrmStationDto stationDto=new CrmStationDto();
			stationDto.setStationId(station.getStationId());
			stationDto.setStudentId(station.getCrmStudent().getStudentId());
			stationDto.setStuName(station.getCrmStudent().getStuName());
			stationDto.setFlag(station.getFlag());
			stationDto.setStaffId(station.getStaffId());
			stationDto.setStaffName(sd.findbyId(station.getStaffId()).getStaffName());
			stationDto.setCreateDate(DateUtil.tranfaceString(station.getCreateDate()));
			stationDto.setBeforeClassId(station.getBeforeClassId());
			stationDto.setBeforeClassName(classdao.findclassbyId(station.getBeforeClassId()).getClassName());
			stationDto.setAfterClassId(station.getAfterClassId());
			stationDto.setAfterClassName(classdao.findclassbyId(station.getAfterClassId()).getClassName());
			stationDtos.add(stationDto);
			
		}
		int count = studentDao.findStationCount();
		int totalpage=(count-1)/size+1;
		return new PageStation(page,size,totalpage,stationDtos);
			
	}


	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#addRunoff(com.qf.pojo.CrmRunoff)
	*/
		
	@Override
	public void addRunoff(CrmRunoff runoff) {
		
		studentDao.addRunoff(runoff);
			
	}


	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#findRunoffById(java.lang.Integer)
	*/
		
	@Override
	public CrmRunoff findRunoffById(Integer runOffId) {
		
		//TODO
		return studentDao.findRunoffById(runOffId);
			
	}


	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#findRunoffByPage(int, int)
	*/
		
	@Override
	public PageRunoff findRunoffByPage(int page, int size) {
		
		List<CrmRunoff> list = studentDao.findRunoffByPage(page, size);
		List<CrmRunoffDto> runoffDtos=new ArrayList<>();
		for(CrmRunoff runoff:list){
			CrmRunoffDto runoffDto=new CrmRunoffDto();
			runoffDto.setRunOffId(runoff.getRunOffId());
			runoffDto.setStudentId(runoff.getCrmStudent().getStudentId());
			runoffDto.setStuName(runoff.getCrmStudent().getStuName());
			runoffDto.setTelephone(runoff.getCrmStudent().getTelephone());
			runoffDto.setQq(runoff.getCrmStudent().getQq());
			runoffDto.setStaffId(runoff.getStaffId());
			runoffDto.setStaffName(sd.findbyId(runoff.getStaffId()).getStaffName());
			runoffDto.setCreateDate(DateUtil.tranfaceString(runoff.getCreateDate()));
			runoffDto.setClassId(runoff.getCrmStudent().getCrmClass().getClassId());
			runoffDto.setClassName(runoff.getCrmStudent().getCrmClass().getClassName());
			runoffDto.setIsRefund(runoff.getIsRefund());
			runoffDto.setRefundAmount(runoff.getRefundAmount());
			runoffDto.setRemark(runoff.getRemark());
			runoffDtos.add(runoffDto);
		}
		int count=studentDao.findRunoffCount();
		int totalpage=(count-1)/size+1;
		return new PageRunoff(page,size,totalpage,runoffDtos);
			
	}


	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#findStudentCountbyother(java.lang.Long)
	*/
		
	@Override
	public int findStudentCountbyother(Long classId) {
		
		//TODO
		return studentDao.findStudentCountbyother(classId);
			
	}


	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#findStationCountbyother(java.lang.Long)
	*/
		
	@Override
	public int findTransCountbyother(Long classId) {
		
		//TODO
		return studentDao.findTransCountbyother(classId);
			
	}


	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#findRunoffCountbyother(java.lang.Long)
	*/
		
	@Override
	public int findAdvanceCountbyother(Long classId) {
		
		//TODO
		return studentDao.findAdvanceCountbyother(classId);
			
	}


	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#findStudentDtobyClassId(java.lang.Long)
	*/
		
	@Override
	public List<CrmStudentDto> findStudentDtobyClassId(Long classId) {
		
		List<CrmStudent> crmStudent = studentDao.findStudentByClassId(classId);
		List<CrmStudentDto> studentDtos=new ArrayList<>();
		for(CrmStudent student:crmStudent){
			CrmStudentDto studentDto=new CrmStudentDto();
			studentDto.setStudentId(student.getStudentId());
			studentDto.setClassId(student.getCrmClass().getClassId());
			studentDto.setClassName(student.getCrmClass().getClassName());
			studentDto.setBeginTime(DateUtil.tranfaceString(student.getCrmClass().getBeginTime()));
			studentDto.setStuName(student.getStuName());
			studentDto.setTelephone(student.getTelephone());
			studentDto.setIdentity(student.getIdentity());
			studentDto.setQq(student.getQq());
			studentDto.setGender(student.getGender());
			studentDto.setMustTuition(student.getMustTuition());
			studentDto.setActualTuition(student.getActualTuition());
			studentDto.setEmail(student.getEmail());
			studentDto.setSchool(student.getSchool());
			studentDto.setEducation(student.getEducation());
			studentDto.setProfessional(student.getProfessional());
			studentDto.setIdentityAddress(student.getIdentityAddress());
			studentDto.setAddress(student.getAddress());
			studentDto.setRemark(student.getRemark());
			studentDto.setHomeTelephone(student.getHomeTelephone());
			studentDto.setHomeContact(student.getHomeContact());
			studentDto.setStatus(student.getStatus());
			studentDtos.add(studentDto);
		}
		 return studentDtos;	
	}


	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#findRunoffCountbyother(java.lang.Long)
	*/
		
	@Override
	public int findRunoffCountbyother(Long classId) {
		
		//TODO
		return studentDao.findRunoffCountbyother(classId);
			
	}


	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmStudentService#findRunoffByPage(int, int)
	*/
		


}

	